package ldkxingzhe.ldkxingzhedemo.menu;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import ldkxingzhe.ldkxingzhedemo.R;


/**
 * Created by liangdengke on 2015/8/21.
 */
public class ActionModeActivity extends Activity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_action_mode);
        ListView listView = (ListView)findViewById(R.id.list_view);

        String[] names = new String[]{"中国","世界","结算机","哈哈"};
        ArrayAdapter adapter = new ArrayAdapter(this,R.layout.list_view_context_menu,R.id.text,names);
        listView.setAdapter(adapter);
        listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                ActionModeActivity.this.startActionMode(mCallback);
                view.setSelected(true);
                return true;
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        Log.d("TAG", "onCreateContextMenu");
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.option_menu,menu);
        return true;
    }
    private ActionMode.Callback mCallback = new ActionMode.Callback() {
        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            Log.d("TAG","onCreateActionMode");
            MenuInflater inflater = getMenuInflater();
            inflater.inflate(R.menu.option_menu,menu);
            return true;
        }

        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            Log.d("TAG","onPrepareActionMode");
            return false;
        }

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            Log.d("TAG","onActionItemClicked");
            return false;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
            Log.d("TAG","onDestroyActionMode");
        }
    };
}
